package cn.wolfcode.mq._02_send_type;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AsyncSendController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("/asyncSendMsg")
    public String asyncSendMsg(String msg){
        rocketMQTemplate.asyncSend("02_asyncsend", msg, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println(sendResult.getMsgId());
                System.out.println(sendResult.getSendStatus());
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("发送失败"+throwable.getMessage());
            }
        });
        return "success";
    }
}
